package com.tang.managementdemo.service.Impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.tang.managementdemo.mapper.LogMapper;
import com.tang.managementdemo.pojo.LogQueryParam;
import com.tang.managementdemo.pojo.OperateLog;
import com.tang.managementdemo.pojo.PageResult;
import com.tang.managementdemo.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;
    @Override
    public PageResult page(LogQueryParam logQueryParam) {
        //1. 分页
        PageHelper.startPage(logQueryParam.getPage(),logQueryParam.getPageSize());
        //2. 查询
        List<OperateLog> page1 = logMapper.page();
//        System.out.println(page1+"+++++++++++++");
//        page1.stream().forEach(item->{
//            System.out.println(item);
//        });
        //3. 强制转化，封装成PageResult
        Page<OperateLog> p= (Page<OperateLog>) page1;
        PageResult pageResult = new PageResult(p.getTotal(), p.getResult());
        return pageResult;
    }
}
